package com.sip.dbadapter.dao.utility;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.sip.dbadapter.dao.base.BaseDao;


public class DaoLoadFactory {





    @SuppressWarnings("rawtypes")
    public static BaseDao getDao(final String daoText) throws Exception {

        
        String[] locations = getConfigLocations();
        ApplicationContext context = new FileSystemXmlApplicationContext(locations);
        BaseDao dao = null;
        if (daoText.equals(DaoNameConstant.REFERENCE_DATA_DAO)) {

            dao =  (BaseDao) context.getBean("ReferenceDataDao");
        }

        if (daoText.equals(DaoNameConstant.API_DAO)) {
            dao = (BaseDao) context.getBean("ApiDao");

        }
        
        if (daoText.equals(DaoNameConstant.SYSTEM_DAO)) {
            dao = (BaseDao) context.getBean("SystemInfoDao");

        }
        
        if (daoText.equals(DaoNameConstant.FILTER_DAO)) {
            dao = (BaseDao) context.getBean("FilteringDao");

        }
        
        if (daoText.equals(DaoNameConstant.TEMPLATE_SAVE_DAO)) {
            dao = (BaseDao) context.getBean("SaveTemplateDao");

        }
        if (daoText.equals(DaoNameConstant.SELECT_TEMPLATE)) {
            dao = (BaseDao) context.getBean("SelectTemplateDao");

        }
        
        if (daoText.equals(DaoNameConstant.GET_REST_URL)) {
            dao = (BaseDao) context.getBean("RestServiceDao");

        }
        
        if (daoText.equals(DaoNameConstant.SCENARIO_RECORD_DAO)) {
            dao = (BaseDao) context.getBean("ScenarioRecordDao");

        }
        if (daoText.equals(DaoNameConstant.RECORD_PLAY_SEARCH_DAO)) {
            dao = (BaseDao) context.getBean("RecordPlaySearchDao");

        }
       
        return dao;
    }
    
    
    
    protected static String[] getConfigLocations() {
        return new String[]{"classpath:config/application.xml"};

    }

}
